package com.cps116.parcelables;


import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

public class MapParcelableData implements Parcelable{

	private List<Coordinate> coords;
	private boolean isContinuous;					//stupid Android glitch...no boolean storage, wtf! 0 = false, 1= true
	private long updateTimeInMillis;
	private String userName;
	private String userId;
	
	public MapParcelableData()
	{
		coords = new ArrayList<Coordinate>();

	}
	
	public MapParcelableData(List<Coordinate> coords, boolean isContinuous, String userName, String userId, long updateTimeInMillis)
	{
		this();
		//make sure NONE OF THESE PARAMS ARE NULL!!!
		this.coords = coords;
		this.isContinuous = isContinuous;
		this.userName = userName;
		this.userId = userId;
		this.updateTimeInMillis = updateTimeInMillis;
	}
	
	
	public int describeContents() {
		//describing the data content
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		
		Log.d("MapParcelableData", " MapParcelableData write to parcel starts");
		
		Log.d("MapParcelableData", " MapParcelableData write coords");
		dest.writeTypedList(coords);
		
		Log.d("MapParcelableData", " MapParcelableData write continuous " + isContinuous);
		dest.writeInt(isContinuous ? 0 : 1 );		//no single boolean storage support...wtf android!
		
		Log.d("MapParcelableData", " MapParcelableData write update time " + updateTimeInMillis);
		dest.writeLong(updateTimeInMillis);
		
		Log.d("MapParcelableData", " MapParcelableData write username " + userName);
		dest.writeString(userName);
		dest.writeString(userId);
	}

	
	public void readFromParcel(Parcel in) {
		
		Log.d("MapParcelableData", " MapParcelableData read from parcel starts");

		//the order of retrieval really matters...
		//read in the coords;
		Log.d("MapParcelableData", " MapParcelableData read from coords starts");
		in.readTypedList(coords, Coordinate.CREATOR);
		
		//get the boolean element back
		isContinuous = in.readInt() == 0;
		Log.d("MapParcelableData", " MapParcelableData read continuous" + isContinuous);

		//get the user preference for update time...
		updateTimeInMillis = in.readLong();
		Log.d("MapParcelableData", " MapParcelableData read update time" + updateTimeInMillis);

		//get the user name
		userName = in.readString();
		Log.d("MapParcelableData", " MapParcelableData read user name" + userName);
		userId = in.readString();
	}
	
	
	
	//create the PARCELABLE CREATOR CLASS
	public static final Parcelable.Creator<MapParcelableData> CREATOR
	= new Parcelable.Creator<MapParcelableData>() {
		
		public MapParcelableData createFromParcel(Parcel in) {
			return new MapParcelableData(in);
		}

		public MapParcelableData[] newArray(int size) {
			return new MapParcelableData[size];
		}
	};	


	private MapParcelableData(Parcel in)
	{
		this();
		readFromParcel(in);
	}

	
	
	
	//THE GETTER AND SETTER METHODS....
	
	
	public List<Coordinate> getCoords() {
		return coords;
	}

	public void setCoords(List<Coordinate> coords) {
		this.coords = coords;
	}

	public boolean isContinuous() {
		return isContinuous;
	}

	public void setContinuous(boolean isContinuous) {
		this.isContinuous = isContinuous;
	}

	public long getUpdateTimeInMillis() {
		return updateTimeInMillis;
	}

	public void setUpdateTimeInMillis(long updateTimeInMillis) {
		this.updateTimeInMillis = updateTimeInMillis;
	}

	public String getUserName() {
		return userName;
	}

	public void setUser(String user) {
		this.userName = user;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	
	
	
	
	
	
}
